/*
 * Copyright (c) 2011
 * Huawei.shen@gmail.com All rights reserved
 *
 * This file is a part os Iplite46 software which is a lightweight IPv4/IPv6
 * protocol stack.
 * 
 * !@file: memcpy.c
 *   describtion:
 *   A simple implemenation of standard c library function 'memcpy'
 */

#include "utils.h"

INT32 _lite_memcpy(PVOID dst, PVOID src, INT32 len)
{
    if (len < 0)
        return ERR_PARM;

    UINT32 * _dst, * _src;
    UINT8  * _dst8, * _src8;
    INT32  _idx32 = 0, _idx8 = 0, _left = len;

    _dst = (UINT32 *) dst;
    _src = (UINT32 *) src;
    _dst8 = (UINT8 *) dst;
    _src8 = (UINT8 *) src;

    while (_left)
    {
        if(_left >= 16)
        {
            _dst[_idx32] = _src[_idx32+1];
            _dst[_idx32] = _src[_idx32+2];
            _dst[_idx32] = _src[_idx32+3];
            _dst[_idx32] = _src[_idx32+4];
            _left -= 16;
            _idx8 += 16;
            _idx32+=4;
            continue;
        }
        else
        {
            _dst8[_idx8] = _src8[_idx8+1];
            _idx8++;
            _left--;
            continue;
        }
    }
    return RET_OK;
}

